- Binary search (LeetCode 704)

Iterative solution: time O(log2(n)) and space O(1)
Recursive solution: time O(log2(n)) and space O(log2(n))

- Palindrome (LeetCode 125)
(Grokepedia.com)
Brute force: time (O(n)) and space (O(n))
Iterative with two pointers: time O(n), and space O(1)
Recursive with two pointers: time O(n), space O(n)

---------------------------------------------------------------------------

Algorithm analysis

Measuring the performance of an algorithm? Time + space complexity

Aim: general dependence of time complexity on the size of the input

Approach#1: Experimental analysis of the performance of the algorithm

Limitations: 
- Experiments can only be performed on a finite set of inputs
- Experimentally, when comparing the performance of algorithm A to algorithm B, experiments
should be done in the same software and hardware environment
- Algorithm has to be implemented

We will try to come up with a way to analyze the running time of the algorithm: 
- Taking into account all inputs
- Evaluate the relative efficiency of two algorithms in a way that is independent of software
and hardware environments
- Base the analysis on a high level description of the algorithm (Pseudo-code)

Solution: Big-Oh notation

Idea: count the number of primitive operations involved in the algorithm:
Examples include: a) Comparing one value to another; b) Evaluating an arithmetic expression; 
c) Indexing into an array...

Why? The number of primitive operations correlates well with the running time of algorithm
How do we dot it?
- Best case scenario: No go
- Average case scenario: out of scope
- Worst case scenario => To account for all inputs

Focus: growth rate is what really matters







 














